package client.panels.headPanels;


import java.util.Vector;

import client.panels.centerPanels.MeteoPanel;
import client.stations.Station;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class HeadPanel extends DockPanel 
{
	
	private class StyleButton extends Button  implements ClickListener 
	{
		public int num ;
		public StyleButton()
		{
			num = 0 ;
			this.addClickListener(this);
		}
		
		public void onClick(Widget sender) 
		{
			Vector styles = new Vector();
			styles.add("ks-Sink");
			styles.add("ks-Info");
			styles.add("ks-List");
			styles.add("ks-SinkItem");
			styles.add("ks-SinkItem-selected");
			styles.add("ks-images-Image");
			styles.add("ks-images-Button");
			styles.add("ks-layouts");
			styles.add("ks-layouts-Label");
			styles.add("ks-layouts-Scroller");
			styles.add("ks-popups-Popup");
			styles.add("infoProse");
			
			
			StyleButton but = (StyleButton)sender ;
			but.setText((String) styles.elementAt(num));
			HeadPanel.getInstance().setStyleName( (String) styles.elementAt(num));
			
			num++;
			if(num > styles.size() -1 )num=0;
		}
	}
	
	
	private class StationButton extends Button  implements ClickListener 
	{
		public Station stat;
		public StationButton(Station s)
		{
			stat = s ;
			this.setText(s.getNom());
			this.addClickListener(this);
		}
		
		public void onClick(Widget sender) 
		{
			StationButton but = (StationButton)sender ;
			MeteoPanel.getInstance().setMeteo(but.stat.getMeteo());
		}
	}
	
	/*---------------------------Singleton Trick-------------------------*/
	private static HeadPanel instance = null ;
	
	private HeadPanel() 
	{
		super();		
		this.setWidth("100%");
		
		Label l = new Label("Skiplan Observer");
		l.setStyleName("ks-layouts-Label");
		this.add(l,DockPanel.CENTER );
		this.setCellHorizontalAlignment(l, DockPanel.ALIGN_CENTER);
		
		this.add(new StyleButton(),DockPanel.NORTH );
	}
	
	public static HeadPanel getInstance() 
	{
		if (null == instance) 
		{
			// Premier appel
			instance = new HeadPanel();
		}
		return instance;
	}
	/*---------------------------------------------------------*/
	
	
	public void setStationLinks(Vector stationList)
	{
		HorizontalPanel hp = new HorizontalPanel();
		for(int i =0 ; i< stationList.size() ; i ++)
		{
			Station stat = (Station) stationList.get(i);
			
			StationButton button = new StationButton(stat);
			button.setText(stat.getNom());	
			hp.add(button);
		}	
		this.add(hp,DockPanel.SOUTH );
	}
	
	

}
